package com.magic.smartcity.view.more.viewmodels

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.magic.smartcity.beans.BusLineBean
import com.magic.smartcity.beans.BusLineStopBean
import com.magic.smartcity.beans.BusOrderBean
import com.magic.smartcity.view.more.models.BusModel

/**
 * @description:
 * @create: Create by Magic on 2022/2/23.
 */
class BusViewModel : ViewModel() {
    private val TAG: String = "BusViewModel"
    private val model = BusModel()

    val busLineList: MutableLiveData<List<BusLineBean>> = MutableLiveData()
    val busLine: MutableLiveData<BusLineBean> = MutableLiveData()
    val busLineStationList: MutableLiveData<List<BusLineStopBean>> = MutableLiveData()
    val busLineStationListById: MutableLiveData<List<BusLineStopBean>> = MutableLiveData()
    val busOrderList: MutableLiveData<List<BusOrderBean>> = MutableLiveData()
    val isAddOrderOk: MutableLiveData<Boolean> = MutableLiveData()
    val isPayOrderOk: MutableLiveData<Boolean> = MutableLiveData()
    fun getLineList() {
        Log.d(TAG, "请求获取巴士全部线路")
        model.getLineList(success = {
            busLineList.postValue(it)
        }, error = {})
    }

    fun getLineById(lineId: Int) {
        Log.d(TAG, "请求获取指定巴士线路${lineId}")
        model.getLineById(lineId, success = {
            busLine.postValue(it)
        }, error = {})
    }

    fun getLineStationList() {
        Log.d(TAG, "请求获取巴士全部线路的站点")
        model.getLineStationList(success = {
            busLineStationList.postValue(it)
        }, error = {})
    }

    fun getLineStationListById(lineId: Int) {
        Log.d(TAG, "请求获取巴士指定线路的站点${lineId}")
        model.getLinesStationById(lineId, success = {
            busLineStationListById.postValue(it)
        }, error = {})
    }

    fun getOrderList() {
        Log.d(TAG, "请求获取用户所有订单")
        model.getOrderList(success = {
            busOrderList.postValue(it)
        }, error = {})
    }

    fun addOrder(busOrderBean: BusOrderBean) {
        Log.d(TAG, "请求新增用户乘车订单")
        model.addOrder(busOrderBean, success = {
            isAddOrderOk.postValue(it == 200)
        }, error = {})
    }

    fun payOrder(busOrderBean: BusOrderBean) {
        Log.d(TAG, "请求支付用户订单id=${busOrderBean.orderNum},支付类型=${busOrderBean.paymentType}")
        model.payOrder(busOrderBean, success = {
            isPayOrderOk.postValue(it == 200)
        }, error = {})
    }
}